clc
clear all
close all


filterLen=16;
N = 1024;
   
w =  dbaux(filterLen);

[lpd,hpd,lpr,hpr] = orthfilt(w); 

vecLp = zeros(1,N);
vecHp = zeros(1,N);
vecLp(1:(filterLen*2)) = lpd;
vecHp(1:(filterLen*2)) = hpd;

vecLp2 = zeros(1,N/2);
vecHp2 = zeros(1,N/2);
vecLp2(1:(filterLen*2)) = lpd;
vecHp2(1:(filterLen*2)) = hpd;
l = fft(vecLp);
t = fft(vecHp);
for k = 1:8
   t2 = fft(vecHp2(1:N/2^k));

   

subplot(2,1,2);
plot(abs(t2));

x = t(1:2^k:N);
   subplot(2,1,1);
plot(abs(x));
norm(x-t2)
end
t2 = fft(vecHp2);

subplot(2,1,1);
plot(abs(t));

subplot(2,1,2);
plot(abs(t2));

x = t(1:2:N);
norm(x-t2)


A = l(1:N/2);
B = l((N/2+1):end);

C = t(1:N/2);
D = t((N/2+1):end);

X = [diag(A) diag( B);diag(C) diag(D)];
x = 1:N/2;
figure
subplot(2,1,1);
v1 = X*[x x]';
plot(real(v1))

subplot(2,1,2);

v2 = [(A.*x + B.*x) (C.*x+D.*x)];
plot(real(v2));

norm(imag(v1)-imag(v2)')

